package com.pai4j.remote.pgc;

import com.pai4j.common.bean.PAIPageResponseBeanUtil;
import com.pai4j.common.bean.PAIResponseBean;
import com.pai4j.domain.vo.request.subjectaccount.SaveArticleRequestVO;
import com.pai4j.domain.vo.response.subjectaccount.ArticleBaseResponseVO;
import com.pai4j.domain.vo.response.subjectaccount.UserArticleStatisticsVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.Map;


@FeignClient(name = "pai4j-pgc-service", contextId = "subjectArticleClient")
public interface SubjectArticleClient {

    /**
     * 专题下发文
     *
     * @param saveArticleRequest
     * @return
     */
    @PostMapping("/pgc-service/subject/article/submit")
    PAIResponseBean<Long> submit(@RequestBody SaveArticleRequestVO saveArticleRequest);

    /**
     * 编辑文章（统一接口，支持草稿和已发布文章的编辑）
     *
     * @param saveArticleRequest 文章保存请求对象（必须包含articleId）
     * @return 文章ID
     */
    @PostMapping("/pgc-service/subject/article/edit")
    PAIResponseBean<Long> editArticle(@RequestBody SaveArticleRequestVO saveArticleRequest); 

    /**
     * 获取专题文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("/pgc-service/subject/article/detail/{id}")
    PAIResponseBean<ArticleBaseResponseVO> detail(@PathVariable Long id,
                                                  @RequestParam(name = "isNeedContent", required = false,
                                                          defaultValue = "true") Boolean isNeedContent);

    /**
     * 查询文章列表: 文章首页的查询，查询全部的文章
     *
     * @param pageNo
     * @param pageSize
     * @return
     */
    @GetMapping("/pgc-service/subject/article/page")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> page(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize);
    
    /**
     * 按照作者查询已发布文章列表
     *
     * @author: CYM-pai
     * @date: 2025/05/11 15:20
     **/
    @GetMapping("/pgc-service/subject/article/pageAuthorAndStatusAndPublish")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageAuthorAndStatusAndPublish(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                         @RequestParam(value = "author", required = false) String author);
    
    /**
     * 按照作者查询草稿文章列表
     *
     * @author: CYM-pai
     * @date: 2025/10/11 15:20
     **/
    @GetMapping("/pgc-service/subject/article/pageAuthorAndStatusAndDraft")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageAuthorAndStatusAndDraft(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                                                @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                                                @RequestParam(value = "author", required = false) String author);
    
    /**
     * 查询已经发布的文章列表
     *
     * @author: CYM-pai
     * @date: 2025/07/12 23:20
     **/
    @GetMapping("/pgc-service/subject/article/pageStatus")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageStatus(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize);
    
    
    /**
     * 批量查询redis，获取文章详情缓存
     *
     * 场景：公众号详情页，一次可能查询10篇文章
     * @param articleIds
     * @return
     */
    @GetMapping("/pgc-service/subject/article/batchGet")
    PAIResponseBean<Map<Long, ArticleBaseResponseVO>> batchGet(@RequestBody List<Long> articleIds);
    
    /**
     * 根据文章id获取文章海报
     *
     * @author: CYM-pai
     * @date: 2025/04/30 19:50
     **/
    @GetMapping("/pgc-service/subject/article/getPoster")
    PAIResponseBean<String> getPoster(@RequestParam("articleId") Long articleId);
    /**
     * 导出文章pdf
     *
     * @author: CYM-pai
     * @date: 2025/04/30 19:50
     **/
    @GetMapping("/pgc-service/subject/article/exportPdf")
    PAIResponseBean<String> exportPdf(@RequestParam("articleId") Long articleId);
    
    /**
     * 导出文章word
     *
     * @author: CYM-pai
     * @date: 2025/04/30 19:50
     **/
    @GetMapping("/pgc-service/subject/article/exportWord")
    PAIResponseBean<String> exportWord(@RequestParam("articleId") Long articleId);
    
    
    /**
     * 查询对应专题的全部存在于数据库中的文章列表
     *
     * @author: CYM-pai
     * @date: 2025/05/11 15:20
     **/
    @GetMapping("/pgc-service/subject/article/publish/{subjectAccount}")
    PAIResponseBean<PAIPageResponseBeanUtil<List<ArticleBaseResponseVO>>> pageSubjectArticleList(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                               @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                               @RequestParam(value = "subjectAccount", required = false) Long subjectAccount);
    
    /**
     *  查询对应专题的已经发布的文章列表： 对于已经存在数据库但是没有到发布时间的文章，
     *  不返回给前端，只返回已经发布的文章列表
     *
     * @author: CYM-pai
     * @date: 2025/07/13 00:06
     **/
    @GetMapping("/pgc-service/subject/article/publishStatus/{subjectAccount}")
    PAIResponseBean<PAIPageResponseBeanUtil<List<ArticleBaseResponseVO>>> pageSubjectArticleListByStatus(@RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
                                                                                                         @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
                                                                                                         @RequestParam(value = "subjectAccount", required = false) Long subjectAccount);
    
    /**
     * 保存草稿文章
     *
     * @param saveArticleRequest 文章保存请求对象
     * @return 文章ID
     */
    @PostMapping("/pgc-service/subject/article/saveDraft")
    PAIResponseBean<Long> saveDraft(@RequestBody SaveArticleRequestVO saveArticleRequest);
    
    /**
     * 分页查询指定作者的草稿文章
     *
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param author 作者
     * @return 草稿文章分页列表
     */
    @GetMapping("/pgc-service/subject/article/drafts/author")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageDraftsByAuthor(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "author") String author);
    
    /**
     * 分页查询指定专题的草稿文章
     *
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param subjectAccount 专题账户
     * @return 草稿文章分页列表
     */
    @GetMapping("/pgc-service/subject/article/drafts/subject")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageDraftsBySubject(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "subjectAccount") String subjectAccount);
    
    /**
     * 将草稿文章发布为待推送状态
     *
     * @param articleId 文章ID
     * @param author 作者（用于权限验证）
     * @param planPushTime 计划推送时间
     * @return 文章ID
     */
    @PostMapping("/pgc-service/subject/article/publishDraft")
    PAIResponseBean<Long> publishDraft(@RequestParam("articleId") Long articleId,
                                       @RequestParam("author") String author,
                                       @RequestParam(value = "planPushTime", required = false) Long planPushTime);
    
    /**
     * 统计指定作者的草稿数量
     *
     * @param author 作者
     * @return 草稿数量
     */
    @GetMapping("/pgc-service/subject/article/drafts/count/author")
    PAIResponseBean<Long> countDraftsByAuthor(@RequestParam("author") String author);
    
    /**
     * 统计指定专题的草稿数量
     *
     * @param subjectAccount 专题账户
     * @return 草稿数量
     */
    @GetMapping("/pgc-service/subject/article/drafts/count/subject")
    PAIResponseBean<Long> countDraftsBySubject(@RequestParam("subjectAccount") String subjectAccount);

    /**
     * 获取用户文章统计信息（包含已发布文章数、草稿数、文章总浏览数）
     *
     * @param author 作者ID
     * @return 用户文章统计信息
     */
    @GetMapping("/pgc-service/subject/article/statistics/user")
    PAIResponseBean<UserArticleStatisticsVO> getUserArticleStatistics(@RequestParam("author") String author);

    /**
     * 分页查询指定作者的文章（支持状态过滤）
     *
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param author 作者
     * @param status 文章状态（可选，null表示查询所有状态）
     * @return 文章分页列表
     */
    @GetMapping("/pgc-service/subject/article/pageAuthorWithStatus")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageAuthorWithStatus(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "author") String author,
            @RequestParam(value = "status", required = false) Integer status);

    /**
     * 分页查询指定专题的文章（支持状态过滤）
     *
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param subjectAccount 专题账户
     * @param status 文章状态（可选，null表示查询所有状态）
     * @return 文章分页列表
     */
    @GetMapping("/pgc-service/subject/article/pageSubjectWithStatus")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageSubjectWithStatus(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "subjectAccount") String subjectAccount,
            @RequestParam(value = "status", required = false) Integer status);

    /**
     * 获取文章详情（带权限控制）
     * 草稿状态的文章只允许作者本人查看
     *
     * @param articleId 文章ID
     * @param isNeedContent 是否需要内容
     * @param currentUserId 当前用户ID（用于权限验证）
     * @return 文章详情
     */
    @GetMapping("/pgc-service/subject/article/detailWithPermission/{id}")
    PAIResponseBean<ArticleBaseResponseVO> detailWithPermission(
            @PathVariable("id") Long articleId,
            @RequestParam(name = "isNeedContent", required = false, defaultValue = "true") Boolean isNeedContent,
            @RequestParam(name = "currentUserId", required = false) String currentUserId);

    /**
     * 删除文章（逻辑删除）
     *
     * @param articleId 文章ID
     * @param author 作者（用于权限验证）
     * @return 是否删除成功
     */
    @DeleteMapping("/pgc-service/subject/article/delete")
    PAIResponseBean<Boolean> deleteArticle(
            @RequestParam("articleId") Long articleId,
            @RequestParam("author") String author);

    /**
     * 恢复已删除的文章
     *
     * @param articleId 文章ID
     * @param author 作者（用于权限验证）
     * @return 是否恢复成功
     */
    @PostMapping("/pgc-service/subject/article/restore")
    PAIResponseBean<Boolean> restoreArticle(
            @RequestParam("articleId") Long articleId,
            @RequestParam("author") String author);

    /**
     * 分页查询指定作者已删除的文章（回收站）
     *
     * @param pageNo 页码
     * @param pageSize 每页大小
     * @param author 作者
     * @return 已删除文章分页列表
     */
    @GetMapping("/pgc-service/subject/article/deleted/author")
    PAIResponseBean<PAIPageResponseBeanUtil<ArticleBaseResponseVO>> pageDeletedByAuthor(
            @RequestParam(value = "pageNo", required = false, defaultValue = "1") Integer pageNo,
            @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize,
            @RequestParam(value = "author") String author);

    /**
     * 更新文章状态
     *
     * @param articleId 文章ID
     * @param author 作者（用于权限验证）
     * @param newStatus 新状态
     * @return 是否更新成功
     */
    @PostMapping("/pgc-service/subject/article/updateStatus")
    PAIResponseBean<Boolean> updateArticleStatus(
            @RequestParam("articleId") Long articleId,
            @RequestParam("author") String author,
            @RequestParam("newStatus") Integer newStatus);
    
    /**
     * 批量逻辑删除文章
     *
     * @param articleIds 文章ID列表
     * @param author 作者（用于权限验证）
     * @return 成功删除的文章数量
     */
    @PostMapping("/pgc-service/subject/article/batch/delete")
    PAIResponseBean<Integer> batchDeleteArticles(
            @RequestBody List<Long> articleIds,
            @RequestParam("author") String author);
    
    /**
     * 批量恢复已删除的文章
     *
     * @param articleIds 文章ID列表
     * @param author 作者（用于权限验证）
     * @return 成功恢复的文章数量
     */
    @PostMapping("/pgc-service/subject/article/batch/restore")
    PAIResponseBean<Integer> batchRestoreArticles(
            @RequestBody List<Long> articleIds,
            @RequestParam("author") String author);
    
    /**
     * 统计某专题下已发布文章的数量
     *
     * @param subjectAccount 专题账户
     * @return 已发布文章数量
     */
    @GetMapping("/pgc-service/subject/article/count/published")
    PAIResponseBean<Long> countPublishedArticlesBySubject(
            @RequestParam("subjectAccount") String subjectAccount);
    
    /**
     * 统计某专题下文章的总数量（不过滤状态）
     *
     * @param subjectAccount 专题账户
     * @return 文章总数量
     */
    @GetMapping("/pgc-service/subject/article/count/total")
    PAIResponseBean<Long> countTotalArticlesBySubject(
            @RequestParam("subjectAccount") String subjectAccount);
    
    /**
     * 物理删除文章（管理员专用）
     *
     * @param articleId 文章ID
     * @param adminUser 管理员用户（用于审计记录）
     * @return 是否删除成功
     */
    @DeleteMapping("/pgc-service/subject/article/physical/delete")
    PAIResponseBean<Boolean> physicalDeleteArticle(
            @RequestParam("articleId") Long articleId,
            @RequestParam("adminUser") String adminUser);
    
    /**
     * 批量物理删除文章（管理员专用）
     *
     * @param articleIds 文章ID列表
     * @param adminUser 管理员用户（用于审计记录）
     * @return 成功删除的文章数量
     */
    @DeleteMapping("/pgc-service/subject/article/physical/batch/delete")
    PAIResponseBean<Integer> batchPhysicalDeleteArticles(
            @RequestBody List<Long> articleIds,
            @RequestParam("adminUser") String adminUser);
    
}
